import 'package:safetymonitor/generated/json/base/json_convert_content.dart';
import 'package:safetymonitor/app/data/entities/application/device_tree_entity.dart';

DeviceTreeEntity $DeviceTreeEntityFromJson(Map<String, dynamic> json) {
  final DeviceTreeEntity deviceTreeEntity = DeviceTreeEntity();
  final int? id = jsonConvert.convert<int>(json['id']);
  if (id != null) {
    deviceTreeEntity.id = id;
  }
  final String? label = jsonConvert.convert<String>(json['label']);
  if (label != null) {
    deviceTreeEntity.label = label;
  }
  final List<DeviceTreeChildren>? children = (json['children'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<DeviceTreeChildren>(e) as DeviceTreeChildren).toList();
  if (children != null) {
    deviceTreeEntity.children = children;
  }
  final String? code = jsonConvert.convert<String>(json['code']);
  if (code != null) {
    deviceTreeEntity.code = code;
  }
  final int? sort = jsonConvert.convert<int>(json['sort']);
  if (sort != null) {
    deviceTreeEntity.sort = sort;
  }
  final int? parentId = jsonConvert.convert<int>(json['parentId']);
  if (parentId != null) {
    deviceTreeEntity.parentId = parentId;
  }
  return deviceTreeEntity;
}

Map<String, dynamic> $DeviceTreeEntityToJson(DeviceTreeEntity entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['id'] = entity.id;
  data['label'] = entity.label;
  data['children'] = entity.children?.map((v) => v.toJson()).toList();
  data['code'] = entity.code;
  data['sort'] = entity.sort;
  data['parentId'] = entity.parentId;
  return data;
}

extension DeviceTreeEntityExtension on DeviceTreeEntity {
  DeviceTreeEntity copyWith({
    int? id,
    String? label,
    List<DeviceTreeChildren>? children,
    String? code,
    int? sort,
    int? parentId,
  }) {
    return DeviceTreeEntity()
      ..id = id ?? this.id
      ..label = label ?? this.label
      ..children = children ?? this.children
      ..code = code ?? this.code
      ..sort = sort ?? this.sort
      ..parentId = parentId ?? this.parentId;
  }
}

DeviceTreeChildren $DeviceTreeChildrenFromJson(Map<String, dynamic> json) {
  final DeviceTreeChildren deviceTreeChildren = DeviceTreeChildren();
  final int? id = jsonConvert.convert<int>(json['id']);
  if (id != null) {
    deviceTreeChildren.id = id;
  }
  final String? label = jsonConvert.convert<String>(json['label']);
  if (label != null) {
    deviceTreeChildren.label = label;
  }
  final String? code = jsonConvert.convert<String>(json['code']);
  if (code != null) {
    deviceTreeChildren.code = code;
  }
  final int? sort = jsonConvert.convert<int>(json['sort']);
  if (sort != null) {
    deviceTreeChildren.sort = sort;
  }
  final int? parentId = jsonConvert.convert<int>(json['parentId']);
  if (parentId != null) {
    deviceTreeChildren.parentId = parentId;
  }
  return deviceTreeChildren;
}

Map<String, dynamic> $DeviceTreeChildrenToJson(DeviceTreeChildren entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['id'] = entity.id;
  data['label'] = entity.label;
  data['code'] = entity.code;
  data['sort'] = entity.sort;
  data['parentId'] = entity.parentId;
  return data;
}

extension DeviceTreeChildrenExtension on DeviceTreeChildren {
  DeviceTreeChildren copyWith({
    int? id,
    String? label,
    String? code,
    int? sort,
    int? parentId,
  }) {
    return DeviceTreeChildren()
      ..id = id ?? this.id
      ..label = label ?? this.label
      ..code = code ?? this.code
      ..sort = sort ?? this.sort
      ..parentId = parentId ?? this.parentId;
  }
}